package com.xiaozhengkeji.bukkit.chunkmanager;

import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

public final class ChunkManager extends JavaPlugin {
    public static ChunkManager Main;

    @Override
    public void onLoad() {
        saveDefaultConfig();
    }

    @Override
    public void onEnable() {
        MessageUtil.server("ChunkManager 启动!");
        Main = this;
        getServer().getPluginManager().registerEvents(new ChunkListener(), this);
        //读取配置文件
        ChunkManagerService.loadConfig();
        //注册命令行
        this.getCommand("ChunkManager").setExecutor(new ChunkManagerCommand());
        //启动异步动态卸载  延迟10分钟开始执行  每隔5分钟循环一次
        new BukkitRunnable() {
            @Override
            public void run() {
                ChunkManagerService.runChunkUninstallTask();
            }
        }.runTaskTimerAsynchronously(JavaPlugin.getProvidingPlugin(ChunkManager.class), 600 * 20, 360 * 20);
    }

    @Override
    public void onDisable() {
        getConfig().set("MAX_CHUNK_SIZE", ChunkManagerService.MAX_CHUNK_SIZE);
        getConfig().set("world", ChunkManagerService.MANAGER_WORLD_LIST);
        //save
        saveConfig();
    }
}
